package com.ketangpai.admin.service.impl;

import com.ketangpai.admin.entity.CourseCatalog;
import com.ketangpai.admin.entity.CourseCatalogSecond;
import com.ketangpai.admin.mapper.CourseCatalogMapper;
import com.ketangpai.admin.service.CourseCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;


@Service
public class CourseCatalogServiceImpl implements CourseCatalogService {

    @Autowired
    private CourseCatalogMapper courseCatalogMapper;

    @Override
    public CourseCatalog[] getCourseCatalog(Integer courseId) {
        CourseCatalog[] courseCatalogs= courseCatalogMapper.getCourseCatalog(courseId);
        for(CourseCatalog courseCatalog:courseCatalogs){
            CourseCatalogSecond[] courseCatalogSeconds=courseCatalogMapper.getCourseCatalogSecond(courseId,courseCatalog.getChapterId());
            for(CourseCatalogSecond courseCatalogSecond:courseCatalogSeconds){
                courseCatalogSecond.setCourseCatalogThird(courseCatalogMapper.getCourseCatalogThird(courseId,courseCatalog.getChapterId(),courseCatalogSecond.getChapterSecondId()));
            }
            courseCatalog.setCourseCatalogSecond(courseCatalogSeconds);
        }
        return courseCatalogs;
    }

}
